<template>
	<view class="container">
		<header>
			<view class='head-nav' @click="$goPath(1)">
				<image src='/static/images/right-white.png' mode='aspectFit|aspectFill|widthFix' alt="" />
				<view>确认订单</view>
			</view>

			<view class='sect-head' @click="onAddressPoputShow">
				<view class='sect-head-top'>
					<image src='https://youpindou.com/miniProgram/image/showImg?imgUrl=/home/ypd/images/address-white.png'
						mode='aspectFit|aspectFill|widthFix' alt="" />
					<view>
						<view>{{ defaultAddress.name }} <text>{{ defaultAddress.phone }}</text></view>
						<view>{{ defaultAddress.province }} {{ defaultAddress.city }} {{ defaultAddress.area }} {{
							defaultAddress.detail }}
						</view>
					</view>
				</view>
			</view>
		</header>

		<section>
			<view class="sect-content">
				<view class='goods-item' v-for="(item, index) in goodsList" :key="index">
					<view class='goods-item-img'>
						<img :src="item.thumbnailUrl" mode='aspectFit|aspectFill|widthFix' alt="" />
					</view>
					<view class='goods-item-content'>
						<view class='goods-item-name'>{{ item.productName }}</view>

						<view class="goods-item-tag" v-if="item.limitation == 1">
							{{ item.limitationSell == 0 ? `限购${item.limitationCount}件` :
								`限购${item.limitationCount}件，第${item.limitationCount + 1}件恢复原价` }}
						</view>
						<view class='goods-item-price' v-if="item.limitation != 1">
							<view>原价￥<text>{{ item.showPrice }}</text>元</view>
							<view>共{{ item.count }}件</view>
						</view>

						<view class='goods-price' v-else>
							<!-- 原来买过 -->
							<view v-if="item.purchasedCount">
								<!-- 还有剩余限购数-->
								<view class="text" v-if="item.limitationCount - item.purchasedCount > 0">
									<view style="display: flex;">
										<view class="padding-text">限购价￥<text class="price">{{ item.limitationPrice }}</text>元</view>
										<!-- 选购数量小于限购数量 -->
										<view v-if="item.count <= (item.limitationCount - item.purchasedCount)">
											共{{ item.count }}件
										</view>
										<!-- 选购数量大于限购数量 -->
										<view v-else>
											共{{ item.limitationCount - item.purchasedCount }}件
										</view>
									</view>
									<view style="display: flex;">
										<view class="padding-text">原价￥<text class="price">{{ item.showPrice }}</text>元</view>
										<!-- 选购数量小于限购数量 -->
										<view v-if="item.count < (item.limitationCount - item.purchasedCount)">
										</view>
										<!-- 选购数量大于限购数量 -->
										<view v-else-if="item.count - (item.limitationCount - item.purchasedCount) == 0"></view>
										<view v-else>
											共{{ item.count - (item.limitationCount - item.purchasedCount) }}件
										</view>
									</view>
								</view>
								<!-- 没有限购了 -->
								<view class="text" v-else>
									<view style="display: flex;">
										<view class="padding-text">限购价￥<text class="price">{{ item.limitationPrice }}</text>元</view>
									</view>
									<view style="display: flex;">
										<view class="padding-text">原价￥<text class="price">{{ item.showPrice }}</text>元</view>
										<view>共{{ item.count }}件</view>
									</view>
								</view>
							</view>

							<!-- 原来没有买过 -->
							<view v-else class="text">
								<view style="display: flex;">
									<view class="padding-text">限购价￥<text class="price">{{ item.limitationPrice }}</text>元</view>
									<view v-if="item.count <= item.limitationCount">共{{ item.count }}件</view>
									<view v-else>共{{ item.limitationCount }}件</view>
								</view>
								<view style="display: flex;">
									<view class="padding-text">原价￥<text class="price">{{ item.showPrice }}</text>元</view>
									<view v-if="item.count <= item.limitationCount"></view>
									<view v-else>共{{ item.count - item.limitationCount }}件</view>
								</view>
							</view>
						</view>

					</view>
				</view>

				<view class="sect-line">
					<image
						src="https://youpindou.com:8083/doudougou/image/showImg?imgUrl=/home/ddg_test/images/faccacac-a9eb-4145-8754-e27e29c1120a.png"
						alt="" mode='widthFix' />
				</view>

				<view class='sect-doudou-card'>
					<view>兜兜卡({{ checkedCardNum }})</view>
					<view @click="onShowPopup()">
						<view>
							<view>￥<text>{{ ddkMoney }}</text></view>
							<image src="/static/images/down-icon.png" mode='aspectFit|aspectFill|widthFix' alt="" />
						</view>
						<view>×<text>{{ checkedCardNum }}</text></view>
					</view>
				</view>

				<view class='sect-balance'>
					<view>账户可用余额</view>
					<view>￥<text>{{ userDetail.availableBalance }}</text></view>
				</view>

				<view class='sect-remark'>
					<view>备注</view>
					<view>
						<textarea placeholder='请输入备注信息' v-model="remark" maxlength="100" />
					</view>
				</view>

				<view class='sect-sum'>
					订单总金额￥<text>{{ totalMoney }}</text>
				</view>

			</view>
		</section>

		<view class='confirmOrder-foot'>
			<view class='confirmOrder-footBtn-bgColor'>
				<view class='footer-btn'>
					<view>
						<view>
							<view class='footer-wxPayPrice'>
								实付￥<text>{{ realityPrice }}</text>
							</view>
							<view class='footer-userPayPrice'>
								兜兜卡×<text>{{ checkedCardNum }}</text>
								余额：<text>{{ userPayPrice == 0 ? userPayPrice : `-${userPayPrice}` }}</text>
							</view>
						</view>
					</view>
					<view @click="goConfirmOrder()">提交支付</view>
				</view>
			</view>
		</view>

		<uni-popup ref="addressPopup">
			<view class='cartAddress-popup'>
				<view class="popup_title">收货地址</view>
				<view class='popup_operate'>
					<view @click="goAddress('add')">新增</view>
					<view @click="goAddress('edit')">管理</view>
				</view>
				<section>
					<view class='address-item' v-for="(item, index) in addressList" :key="index" @click="onCheckAddress(item)">
						<view>
							<img class='address-item-defaultImg' src="/static/images/address.png" mode='aspectFit|aspectFill|widthFix'
								alt="" v-if="item.isDefault == 1" />
							<view class='address-item-name' v-else>{{ item.isDefaultName }}</view>

							<view class='address-item-info'>
								<view class='address-item-info-contacts'>
									<view>{{ item.name }}</view>
									<view>{{ item.phone }}</view>
									<view class='default' v-if="item.isDefault == 1">默认</view>
								</view>
								<view class='address-item-info-address'>{{ `${item.province}${item.city}${item.area} ${item.detail}` }}
								</view>
							</view>
						</view>
						<view class='address-item-check'>
							<u-radio-group v-model="item.isChecked">
								<u-radio activeColor="#32B499" shape="circle" :name="item.isChecked"></u-radio>
							</u-radio-group>
						</view>
					</view>
				</section>
			</view>
		</uni-popup>

		<uni-popup ref="doudouCardPopup" bottom>
			<view class='doudouCard-popup'>
				<view class='doudouCard-popup-head'>
					兜兜卡({{ ddkList.length }})
				</view>
				<view class='doudouCard-popup-sect'>
					<image src='https://youpindou.com/miniProgram/image/showImg?imgUrl=/home/ypd/images/ddk-checked.png' mode='aspectFit|aspectFill|widthFix' alt="" />
					<view class='doudouCard-popup-sect-child'>
						<view class='have-num'>{{ ddkList.length }}</view>
						<view class='doudouCard-popup-sect-child_right'>
							<view class='card-num'>
								<view>
									<u-icon color="#333" size="16" name="minus" @click="changeNum('minus')"></u-icon>
								</view>
								<view>{{ checkedCardNum }}</view>
								<view>
									<u-icon color="#333" size="16" name="plus" @click="changeNum('add')"></u-icon>
								</view>
							</view>
							<view>面值300/张</view>
						</view>
					</view>
				</view>
				<view class='doudouCard-popup-btn'>
					<view @click="onDdkPopupClose">确定</view>
				</view>
			</view>
		</uni-popup>

		<uni-popup ref="needPayPopup" style="height: 100%;width: 100%;">
			<view class='modal-confirm'>
				<view @click.stop>
					<view class='modal-confirm-section'>
						<view class='needPay-money'>￥<view>{{ realityPrice }}</view>
						</view>
						<view class='toast-pay'>您的帐户余额不足，剩余请用其它方式支付</view>
						<view class='pay-type'>
							<u-radio-group v-model="needPayType" placement="column">
								<u-radio :name="2" activeColor="#32B499" :customStyle="{ marginBottom: '12px' }">
									<view class='pay-type-cont' @click="needPayType = 2">
										<image
											src="https://youpindou.com:8083/doudougou/image/showImg?imgUrl=/home/ddg_test/images/973a7651-00ae-4dc0-8b73-78952c0694f9.png"
											alt="" mode='aspectFit|aspectFill|widthFix' />
										<view>支付宝</view>
									</view>
								</u-radio>

								<u-radio :name="1" activeColor="#32B499">
									<view class='pay-type-cont' @click="needPayType = 2">
										<image
											src="https://youpindou.com:8083/doudougou/image/showImg?imgUrl=/home/ddg_test/images/49eb0d0e-e41b-4b0d-80d8-dadaba15d396.png"
											alt="" mode='aspectFit|aspectFill|widthFix' />
										<view>微信支付</view>
									</view>
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view class='modal-confirm-footer'>
						<view @click="handleCancel">取消</view>
						<view @click="handleOk">确定</view>
					</view>
				</view>
			</view>
		</uni-popup>

		<u-popup :show="showLoading" @open="showLoading = true" mode="center" bgColor="transparent">
			<view class="loading_popup">
				<view class="loading_title">
					尊敬的用户：
				</view>
				<view class="loading_box" v-html="loadingValue">
				</view>
				<view class="loading_btn" @click="showLoading = false">
					确认
				</view>
			</view>
		</u-popup>

		<u-modal :show="confirmVisible" showCancelButton content="您确定使用账户余额支付?" closeOnClickOverlay @confirm="confirm"
			@cancel="confirmVisible = false"></u-modal>

		<u-modal :show="toastVisable" showCancelButton content="当前购买未使用兜兜卡，将无法成为会员，需要继续购买吗？" closeOnClickOverlay
			@confirm="toastConfirm" @cancel="toastVisable = false"></u-modal>

	</view>
</template>

<script>
	import {
		getUserInfo
	} from '@/common/auth';


	export default {
		data() {
			return {
				showLoading: false,
				loadingValue: '',
				visiable: false, //选择兜兜卡弹窗 展示隐藏
				ddkList: [], //兜兜卡列表
				checkedCardNum: 0, //兜兜卡使用数量
				totalMoney: 0, //订单总金额
				ddkMoney: 0, //已选择兜兜卡金额
				selectDdkList: [], //已选择兜兜卡列表
				userPayPrice: 0, //用户余额扣除的金额
				realityPrice: 0, //需要微信/支付宝支付的金额
				addressList: [], //收货地址列表
				defaultAddress: {}, //选择的收货地址 默认取列表的第一条
				goodsList: [], //商品列表
				remark: '', //备注信息
				newOrderId: '', //订单id
				userDetail: {}, //用户信息
				needPayType: 2, //支付方式 
				wechat: '',
				confirmVisible: false,
				toastVisable: false,
			}
		},
		onLoad(options) {
			this.goodsList = JSON.parse(decodeURIComponent(options.goodsList))
			this.defaultAddress = JSON.parse(decodeURIComponent(options.defaultAddress))
			
			// #ifndef MP-WEIXIN
			plus.share.getServices(function(s) {
				let share = {};
				for (let i = 0; i < s.length; i++) {
					let t = s[i];
					share[t.id] = t;
				}
				let wechat = share['weixin'];
				this.wechat = wechat;
			}, function(e) {});
			// #endif

		},
		onShow() {
			let userInfo = getUserInfo()
			this.getAddressList(userInfo);
			this.getUserDetail(this.goodsList, userInfo);
		},
		methods: {
			// 获取公告弹窗内容
			async getLoading() {
				let result = await this.$request.systemSettingsGet({
					key: 'home_page_windows'
				})
				this.loadingValue = '&nbsp&nbsp&nbsp&nbsp' + result.data?.settingValue;
			},
			changeWechat() {
				console.log('111')
				// this.payWay = 1
				this.showLoading = true
				this.$refs.needPayPopup.close();
				this.getLoading()
			},
			//获取收货地址列表
			async getAddressList(userInfo) {
				await this.$request.myAddress({
					userId: userInfo.userId
				}).then(res => {
					if (res.code == 200 && res.isSuccess) {
						res.data.map(item => {
							item.isChecked = false;
							if (!item.isDefault) {
								item.isDefaultName = item.name.slice(0, 1);
							};
							if (item.id == this.defaultAddress.id) {
								item.isChecked = true;
							}
						});
						this.addressList = res.data;
					}
				});
			},

			//收货地址弹窗展示
			onAddressPoputShow() {
				this.$refs.addressPopup.open('bottom');
			},

			//选择收货地址
			onCheckAddress(detail) {
				let addressDetail = {};
				let list = this.addressList;
				list.map(item => {
					if (item.id == detail.id) {
						item.isChecked = true;
						addressDetail = detail;
					} else {
						item.isChecked = false;
					}
				});

				if (list.length == 1) {
					list[0].isChecked = true;
				}

				this.addressList = list;
				this.defaultAddress = addressDetail;
				this.$refs.addressPopup.close();
			},

			//新建/修改收货地址
			goAddress(type) {
				let addressItem = {};
				this.addressList.map(item => {
					if (item.isChecked) {
						addressItem = item;
					};
				});
				this.$goPath(2, `/pagesA/pocketShop/mine/editAddress?type=${type}&&addressItem=${JSON.stringify(addressItem)}}`)
			},

			//获取个人信息
			async getUserDetail(list, userInfo) {
				await this.$request.userInformation({
					userId: userInfo.userId
				}).then(res => {
					const {
						code,
						isSuccess,
						data
					} = res;
					if (code == 200 && isSuccess) {
						let sum = 0.00;
						list.map(item => {
							if (item.limitation == 0) {
								sum += item.totalPrice;
							} else {
								// 以前没买过
								if (!item.purchasedCount) {
									if (item.count <= item.limitationCount) {
										// 还有限购数量
										sum += item.count * item.limitationPrice
									} else {
										// 没有限购数量
										sum += (item.limitationCount * item.limitationPrice) + (item.count - item
											.limitationCount) * item.showPrice
									}
								} else {
									// 以前买过
									if (item.purchasedCount >= item.limitationCount) {
										// 以前直接买超
										sum += item.count * item.showPrice
									} else {
										// 以前没有买超
										// sum+=item.count*item.limitationPrice
										if ((item.count + item.purchasedCount) <= item.limitationCount) {
											// 现在和以前加起来都没有买超
											sum += item.count * item.limitationPrice
										} else {
											sum += (item.limitationCount - item.purchasedCount) * item.limitationPrice + (item
												.count - (item.limitationCount - item.purchasedCount)) * item.showPrice
										}
									}
								}



								// if (!item.purchasedCount) {
								// 	if (item.count <= item.limitationCount) {
								// 		// 还有限购数量
								// 		sum += item.count * item.showPrice
								// 	} else {
								// 		// 没有限购数量
								// 		sum += (item.limitationCount * item.showPrice) + (item.count - item.limitationCount) * item.limitationPrice
								// 	}
								// } else {
								// 	// 以前买过
								// 	if (item.purchasedCount >= item.limitationCount) {
								// 		// 以前直接买超
								// 		sum += item.count * item.limitationPrice
								// 	} else {
								// 		// 以前没有买超
								// 		// sum+=item.count*item.limitationPrice
								// 		if ((item.count + item.purchasedCount) <= item.limitationCount) {
								// 			// 现在和以前加起来都没有买超
								// 			sum += item.count * item.showPrice
								// 		}else{
								// 			sum+=(item.limitationCount - item.purchasedCount) * item.showPrice + (item.count - (item.limitationCount - item.purchasedCount)) * item.limitationPrice 
								// 		}
								// 	}
								// }


								// 超出限购
								// if (item.purchasedCount >= item.limitationCount) {
								// 	sum += item.limitationPrice * item.count
								// } else if ((item.count + item.purchasedCount) > item.limitationCount) {
								// 	// 购物车数量+已购数量<=限购数量
								// 	sum += ((item.limitationPrice * (item.limitationCount - item.purchasedCount)) + ((item.count - (item.limitationCount - item.purchasedCount)) * item.showPrice))
								// } else {
								// 	sum += item.limitationPrice * item.count
								// }
							}
						});

						this.totalMoney = sum.toFixed(2);
						this.userDetail = data;
						this.getDdkList(data, sum);
					};
				});
			},

			//获取兜兜卡列表
			async getDdkList(userDetail, sum) {
				await this.$request.cardFindByList({
					userId: userDetail.userId
				}).then(res => {
					if (res.code == 200 && res.isSuccess) {
						this.ddkList = res.data;
						if (sum >= 300) {
							// let needCardNum = parseInt(sum/300);
							let num = 0;
							if (sum >= 300 && sum <= 899) num = 1;
							if (sum >= 900 && sum <= 2999) num = 3;
							if (sum >= 3000 && sum <= 8999) num = 10;
							if (sum >= 9000 && sum <= 29999) num = 30;
							if (sum >= 30000) num = 100;

							if (num <= res.data.length) {
								let cadIdList = [];
								for (let i = 0; i < num; i++) {
									cadIdList.push(res.data[i].id);
								};
								const sumPrice = num * 300;
								this.ddkMoney = sumPrice;
								this.selectDdkList = cadIdList;
								this.checkedCardNum = num;

							} else {
								let cadIdList = [];
								num = res.data.length;
								res.data.map(item => {
									cadIdList.push(item.id);
								});
								const sumPrice = num * 300;

								this.ddkMoney = sumPrice;
								this.selectDdkList = cadIdList;
								this.checkedCardNum = num;
							}

							let needPayPrice = 0;
							if (Number(sum - num * 300) == 0) {
								needPayPrice = '0.00';
							} else if (Number(sum - num * 300) > 0) {
								needPayPrice = Number(sum - num * 300).toFixed(2);
							} else {
								needPayPrice = '0.00';
							}

							if (userDetail.availableBalance > needPayPrice) {
								let pirce = userDetail.availableBalance - (userDetail.availableBalance - needPayPrice);
								this.userPayPrice = Number(pirce)?.toFixed(2);
								needPayPrice = '0.00';
							} else {
								this.userPayPrice = Number(userDetail.availableBalance)?.toFixed(2);
								needPayPrice = Number(needPayPrice - userDetail.availableBalance)?.toFixed(2)
							}

							this.realityPrice = needPayPrice;
						} else {
							if (userDetail.availableBalance >= sum) {
								let pirce = userDetail.availableBalance - (userDetail.availableBalance - sum);
								this.userPayPrice = Number(pirce)?.toFixed(2);
								this.realityPrice = '0.00';
							} else {
								let pirce = sum - userDetail.availableBalance;
								this.userPayPrice = Number(userDetail.availableBalance)?.toFixed(2);
								this.realityPrice = pirce?.toFixed(2);
							}
						}

					}
				});
			},

			//选择兜兜卡弹窗展示
			onShowPopup() {
				this.$refs.doudouCardPopup.open('bottom');
			},

			//选择兜兜卡弹窗关闭
			onDdkPopupClose() {
				this.$refs.doudouCardPopup.close();
			},

			//选择兜兜卡使用数量
			changeNum(type) {
				const {
					checkedCardNum,
					totalMoney,
					userDetail,
					ddkList,
					ddkMoney
				} = this;
				let num = checkedCardNum;
				let sumPrice = 0;
				if (type == 'minus') {
					if (num > 0) {
						num--;
						sumPrice = num * 300;
						this.ddkMoney = sumPrice;
						if (totalMoney - userDetail.availableBalance - num * 300 > 0) {
							this.realityPrice = Number(totalMoney - userDetail.availableBalance - num * 300).toFixed(2);
						} else {
							this.realityPrice = '0.00';
						}

						if (userDetail.availableBalance + num * 300 > totalMoney) {
							let pirce = userDetail.availableBalance - Math.abs(userDetail.availableBalance + num * 300 - totalMoney);
							this.userPayPrice = Number(pirce)?.toFixed(2);
						} else {
							this.userPayPrice = Number(userDetail.availableBalance)?.toFixed(2);
						}
					}
				} else {
					if (ddkList.length != 0) {
						if (totalMoney >= 300) {
							if (num < ddkList.length) {
								if (ddkMoney + 300 < totalMoney || ddkMoney + 300 == totalMoney) {
									num++;
									sumPrice = num * 300;
									this.ddkMoney = sumPrice;
									if (totalMoney - userDetail.availableBalance - num * 300 > 0) {
										this.realityPrice = Number(totalMoney - userDetail.availableBalance - num * 300).toFixed(2);
									} else {
										this.realityPrice = '0.00';
									}

									if (userDetail.availableBalance + num * 300 > totalMoney) {
										let pirce = userDetail.availableBalance - Math.abs(userDetail.availableBalance + num * 300 -
											totalMoney);
										this.userPayPrice = Number(pirce)?.toFixed(2);
									} else {
										this.userPayPrice = Number(userDetail.availableBalance)?.toFixed(2);
									}
								}
							} else {
								this.$toast('当前账户兜兜卡数量不足，请购买后重试')
							}
						} else {
							this.$toast('订单金额小于兜兜卡面值，请使用其它方式支付')
						}
					} else {
						this.$toast('当前账户暂无兜兜卡，请购买后重试')
					}
				};
				let cadIdList = [];
				for (let i = 0; i < num; i++) {
					cadIdList.push(ddkList[i].id);
				};
				this.selectDdkList = cadIdList;
				this.checkedCardNum = num;
			},

			//创建订单
			goConfirmOrder() {
				if (this.selectDdkList.length == 0) {
					this.toastVisable = true;
					return;
				}

				if (Number(this.realityPrice)) {
					// #ifdef MP-WEIXIN
					this.handleOk()
					// #endif
					
					// #ifndef MP-WEIXIN
					this.$refs.needPayPopup.open('center');
					// #endif
					
				} else {
					this.confirmVisible = true;
				}
			},

			//未用兜兜卡继续购买
			toastConfirm() {
				this.toastVisable = false;
				if (Number(this.realityPrice)) {
					// #ifdef MP-WEIXIN
					this.handleOk()
					// #endif
					
					// #ifndef MP-WEIXIN
					this.$refs.needPayPopup.open('center');
					// #endif
				} else {
					this.confirmVisible = true;
				}
			},

			//二次确认使用余额支付
			confirm() {
				this.handleOk();
			},
			handleOk() {
				const {
					goodsList,
					defaultAddress,
					selectDdkList,
					realityPrice,
					needPayType,
					userDetail,
					remark
				} = this;
				const shoppingIdList = [];
				goodsList.map(item => {
					shoppingIdList.push(item.id);
				});
				const param = {
					addressId: defaultAddress.id,
					userId: userDetail.userId,
					shoppingIdList,
					remark
				};
				this.$request.createOrder(param).then(res => {
					if (res.code == 200 && res.isSuccess) {
						// #ifdef MP-WEIXIN
							this.orderWeixinPayFun(res.data, selectDdkList, realityPrice, needPayType)
						// #endif
						
						// #ifndef MP-WEIXIN
							this.orderPayFun(res.data, selectDdkList, realityPrice, needPayType);
						// #endif
					} else {
						this.$toast(res.msg)
					}
				});

			},
			//小程序微信支付
			orderWeixinPayFun(orderId, cadIdList, realityPrice, needPayType) {
				// payWay:0是微信小程序,1微信2支付宝
				const param = {
					userId: this.userDetail.userId,
					orderId,
					cadIdList,
					payWay: 0
				}
				uni.showToast({
					title: '加载中',
					icon: 'loading'
				});
				this.$request.orderPay(param).then(res => {
					if(res.data.isNeedPay) {
						const data = JSON.parse(res.data.message);
						const {
							timeStamp,
							nonceStr,
							signType,
							paySign
						} = data;
						uni.requestPayment({
							timeStamp,
							nonceStr,
							package: data.package,
							signType,
							paySign,
							success: function(request) {
								console.log(request, 'request');
								// 支付成功
								uni.redirectTo({
									url: `/pagesA/pocketShop/mine/orderDetail?orderId=${orderId}`
								});
							},
							fail: function(error) {
								console.log(error, 'error');
								// 支付失败
								uni.showToast({
									title: '支付失败',
									icon: 'none'
								});
							}
						});
					} else {
						uni.showToast({
							title: '支付成功',
							icon: 'success'
						});
						uni.redirectTo({
							url: `/pagesA/pocketShop/mine/paySuccess?orderId=${orderId}`
						});
					}
					
				})
			},
			//提交支付
			orderPayFun(orderId, cadIdList, realityPrice, needPayType) {
				const param = {
					userId: this.userDetail.userId,
					orderId,
					cadIdList
				}

				if (Number(realityPrice)) {
					param.payWay = Number(needPayType);
				}

				uni.showToast({
					title: '加载中',
					icon: 'loading'
				});

				this.$request.orderPay(param).then(res => {
					if (res.code == 200 && res.isSuccess) {
						if (res.data.isNeedPay) {
							if (needPayType == 2) {
								const dateObj = res.data.message;
								let reg = /(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g;
								plus.runtime.openURL(encodeURI(dateObj.match(reg)[0]));
								uni.redirectTo({
									url: `/pagesA/pocketShop/mine/orderDetail?orderId=${orderId}`
								});
							} else {
								//余额不足需要跳转微信支付
								let dateObj = JSON.parse(res.data.message);
								plus.share.getServices(service => {
									let weixin = service.find(i => i.id === 'weixin')
									if (weixin) {
										weixin.launchMiniProgram({
											id: "gh_f3a8a1c4d7cf",
											path: `/pages/payIndex/payIndex?rc_result=${JSON.stringify(dateObj)}`,
											type: 0,
											webUrl: ''
										}, res => {}, err => {})
									} else {
										// 没有获取到微信分享服务
										console.log('没有获取到微信分享服务');
									}

								}, err => {
									// 获取分享服务列表失败
									console.log(err);
								})
							}

						} else {
							uni.showToast({
								title: '支付成功',
								icon: 'success'
							});
							uni.redirectTo({
								url: `/pagesA/pocketShop/mine/paySuccess?orderId=${orderId}`
							});

						}
					} else {
						uni.showToast({
							title: '支付失败',
							icon: 'none'
						});
					}
				});
			},

			//取消支付
			handleCancel() {
				if (Number(this.realityPrice)) {
					this.$refs.needPayPopup.close();
				}
			},

		},

	}
</script>
<style>
	.container {
		width: 100%;
		height: 100vh;
		font-size: 14px;
		font-family: 'PingFang SC-Medium';
		background-color: #FED14E;
		display: flex;
		flex-direction: column;
		overflow: auto;
	}

	.container>header {
		width: 100%;
		padding: 50px 12px 30px;
		border-radius: 0 0 20px 20px;
		box-sizing: border-box;
		color: #fff;
		background-color: #32B499;
		background-image: url('https://youpindou.com/miniProgram/image/showImg?imgUrl=/home/ypd/images/homeTopIcon.png');
		background-size: 100% auto;
		background-repeat: no-repeat;
	}

	.head-nav {
		display: flex;
		align-items: center;
		font-size: 18px;
		font-family: 'PingFang SC-Bold';
	}

	.head-nav>image {
		width: 8px;
		height: 16px;
		display: block;
		margin-right: 3px;
	}

	.sect-head {
		border-radius: 8px;
		box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.01);
		padding: 0 12px;
		box-sizing: border-box;
		color: #fff;
	}

	.sect-head .sect-head-top {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		padding: 12px 0;
		font-family: 'PingFang SC-Medium';
		box-sizing: border-box;
	}

	.sect-head .sect-head-top image {
		width: 24px;
		height: 24px;
		display: block;
	}

	.sect-head .sect-head-top>view {
		flex: 1;
		padding-left: 12px;
		box-sizing: border-box;
	}

	.sect-head .sect-head-top>view>view:first-child {
		font-family: 'PingFang SC-Bold';
		font-size: 16px;
	}

	.sect-head .sect-head-top>view>view:first-child text {
		font-family: 'DIN-Regular';
		margin-left: 5px;
	}

	.sect-head .sect-head-top>view>view:last-child {
		font-size: 14px;
	}

	.sect-head .sect-head-top>view>view:last-child text {
		font-family: 'DIN-Regular';
	}

	.container>section {
		/* height: 100%; */
		box-sizing: border-box;
		padding: 0 12px 90px;
		box-sizing: border-box;
		overflow-y: auto;
		position: relative;
		top: -30px;
		overflow: visible;
	}

	.sect-content {
		/* height: 100%; */
		border-radius: 20px;
		background-color: #fff;
		padding: 12px;
		box-sizing: border-box;
		padding-bottom: 30px;
		box-sizing: border-box;
	}

	.goods-item {
		display: flex;
		align-items: center;
		margin-bottom: 12px;
	}

	.goods-item .goods-item-img {
		width: 90px;
		height: 90px;
	}

	.goods-item-img img {
		width: 100%;
		height: 100%;
		display: block;
		border-radius: 4px;
	}

	.goods-item .goods-item-content {
		flex: 1;
		min-height: 90px;
		padding-left: 12px;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.goods-item .goods-item-name {
		font-size: 12px;
		font-family: 'PingFang SC-Bold';
		font-weight: bold;
		color: #333333;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		/* 设置超过为省略号的行数 */
		overflow: hidden;
	}

	.text {
		font-size: 13px;
		color: #999999;
		font-family: 'PingFang SC-Bold';
	}

	.padding-text {
		padding-right: 32rpx;
		display: flex;
		align-items: center;
	}

	.goods-item-tag {
		font-size: 10px;
		width: fit-content;
		padding: 2px 5px;
		margin-top: 4px;
		background: #FDF3F3;
		color: #EA5F5F;
		font-family: 'PingFang SC-Medium';
		border-radius: 4px;
		box-sizing: border-box;
	}

	.goods-item .goods-price {
		display: flex;
		align-items: center;
		justify-content: flex-start;
	}

	.goods-item-price {
		display: flex;
		align-items: flex-end;
		margin-right: 12px;
	}

	.price {
		font-size: 16px;
		color: #333333;
		font-family: 'DIN-Bold';
	}

	.goods-item .goods-item-price>view:first-child>text {
		font-size: 16px;
		color: #333333;
		font-family: 'DIN-Bold';
	}

	.goods-item .goods-item-price>view:last-child {
		margin-left: 5px;
		color: #999999;
	}


	.sect-line {
		width: 100%;
		margin: 12px 0;
	}
	.sect-line image {
		width: 100%;
	}

	.sect-doudou-card {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		padding-top: 12px;
		margin-bottom: 12px;
		box-sizing: border-box;
	}

	.sect-doudou-card>view:first-child {
		font-family: 'PingFang SC-Medium';
		color: #333;
		font-size: 16px;
	}

	.sect-doudou-card>view:last-child>view:first-child {
		color: #EA5F5F;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.sect-doudou-card>view:last-child>view:first-child text {
		font-family: 'DIN-Medium';
		font-size: 16px;
	}

	.sect-doudou-card>view:last-child>view:first-child image {
		width: 14px;
		height: 8px;
		display: block;
		margin-left: 10px;
	}

	.sect-doudou-card>view:last-child>view:last-child {
		font-size: 14px;
		text-align: right;
		padding-right: 25px;
		box-sizing: border-box;
	}

	.sect-doudou-card>view:last-child>view:last-child text {
		font-family: 'DIN-Medium';
	}

	.sect-balance {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 12px;
		font-family: 'PingFang SC-Medium';
		color: #333;
		font-size: 16px;
	}

	.sect-balance>view:last-child {
		color: #EA5F5F;
	}

	.sect-balance text {
		font-family: 'DIN-Medium';
		font-size: 16px;
	}

	.sect-remark {
		width: 100%;
		margin-bottom: 32px;
	}

	.sect-remark textarea {
		width: 100%;
		height: 100px;
		margin-top: 5px;
		border: 1px solid rgba(0, 0, 0, 0.5);
		padding: 10px;
		box-sizing: border-box;
		border-radius: 8px;
	}

	.sect-sum {
		font-size: 14px;
		text-align: right;
	}

	.sect-sum text:first-child {
		font-family: 'DIN-Medium';
	}

	.sect-sum text:last-child {
		font-family: 'DIN-Bold';
		color: #EA5F5F;
		font-size: 20px;
	}

	.confirmOrder-foot {
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		padding: 0 12px;
		padding-bottom: 15px;
		box-sizing: border-box;
		color: #fff;
		background-color: #fff;
	}

	.confirmOrder-foot>view {
		height: 100%;
		text-align: center;
		padding: 0 12px;
		padding-top: 12px;
		padding-bottom: calc((env(safe-area-inset-bottom)));
		box-sizing: border-box;
	}

	.confirmOrder-foot>view .footer-btn {
		width: 100%;
		height: 3rem;
		border-radius: 23px;
		display: flex;
		align-items: center;
	}

	.confirmOrder-foot>view .footer-btn>view:first-child {
		flex: 1;
		height: 100%;
		display: flex;
		align-items: center;
		font-size: 14px;
		background-color: #333333;
		border-radius: 23px 0 0 23px;
		padding-left: 30px;
		box-sizing: border-box;
	}

	.confirmOrder-foot>view .footer-btn>view:first-child>view {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		justify-content: flex-start;
	}

	.confirmOrder-foot>view .footer-btn .footer-wxPayPrice>text {
		font-family: 'DIN-Bold';
		font-size: 20px;
		margin-right: 3px;
	}

	.confirmOrder-foot>view .footer-btn .footer-userPayPrice>text {
		font-family: 'DIN-Medium';
		margin-right: 4px;
	}

	.confirmOrder-foot>view .footer-btn .footer-userPayPrice {
		font-size: 12px;
	}

	.confirmOrder-foot>view .footer-btn>view:last-child {
		width: 6.5rem;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 14px;
		font-family: 'PingFang SC-Medium';
		background-color: #32B499;
		height: 100%;
		border-radius: 0 23px 23px 0;
	}

	.cartAddress-popup {
		height: 50vh;
		overflow-y: scroll;
		padding: 12px;
		color: #333333;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		font-size: 14px;
		border-radius: 20px 20px 0 0;
		background-color: #fff;
	}

	.cartAddress-popup .popup_title {
		border-bottom: 1px solid rgba(241, 241, 241, 0.8);
		display: flex;
		justify-content: center;
		align-items: center;
		padding-bottom: 12px;
		box-sizing: border-box;
		font-size: 16px;
		font-family: 'PingFang SC-Bold';
		font-weight: bold;
	}

	.cartAddress-popup .popup_operate {
		display: flex;
		flex-direction: row-reverse;
		margin-bottom: 12px;
		padding-top: 12px;
		box-sizing: border-box;
	}

	.popup_operate>view {
		margin-left: 20px;
	}

	.cartAddress-popup section {
		flex: 1;
		overflow-y: scroll;
	}

	.cartAddress-popup section .address-item>view:first-child {
		flex: 1;
		display: flex;
	}

	.address-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 16px;
	}

	.address-item .address-item-defaultImg {
		width: 2.5rem;
		height: 2.5rem;
		display: block;
	}

	.address-item-name {
		width: 2.5rem;
		height: 2.5rem;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #32B499;
		color: #fff;
		font-size: 16px;
		font-family: 'PingFang SC-Bold';
		border-radius: 50% 50%;
	}

	.address-item .address-item-info {
		flex: 1;
		padding-left: 6px;
		box-sizing: border-box;
		color: #999;
	}

	.address-item .address-item-info .address-item-info-contacts {
		display: flex;
		align-items: center;
		color: #333333;
	}

	.address-item-info-contacts>span:first-child {
		font-size: 16px;
		font-family: 'PingFang SC-Bold';
		margin-right: 5px;
	}

	.address-item-info-contacts>view:nth-child(2) {
		font-family: 'DIN-Regular';
	}

	.address-item-info-contacts>.default {
		border-radius: 2px;
		display: flex;
		justify-content: center;
		align-items: center;
		border: 1px solid #32B499;
		font-size: 12px;
		color: #32B499;
		margin-left: 5px;
		padding: 0 2px;
		box-sizing: border-box;
	}

	.address-item .address-item-info-icon {
		width: 1.2rem;
		height: 1.2rem;
		display: block;
		margin-left: 12px;
	}

	.doudouCard-popup {
		height: 45vh;
		padding: 0 12px;
		box-sizing: border-box;
		position: relative;
		background-color: #fff;
		border-radius: 20px 20px 0 0;
	}

	.doudouCard-popup .doudouCard-popup-head {
		text-align: center;
		padding: 12px 0;
		border-bottom: 1px solid rgba(241, 241, 241, 0.8);
		font-size: 16px;
		color: #333;
		font-family: 'PingFang SC-Bold';
	}

	.doudouCard-popup .doudouCard-popup-sect {
		width: 100%;
		height: 8.2rem;
		position: relative;
	}

	.doudouCard-popup .doudouCard-popup-sect>image {
		width: 100%;
		height: 100%;
		display: block;
		margin-top: 12px;
	}


	.doudouCard-popup-sect-child {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 7.5rem;
		display: flex;
		justify-content: space-between;
		padding: 12px 16px;
		box-sizing: border-box;
	}

	.doudouCard-popup-sect-child .have-num {
		width: 7.5rem;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 36px;
		font-family: 'DIN-Bold';
		color: #FFFFFF;
		padding-top: 4rem;
		box-sizing: border-box;
	}


	.doudouCard-popup .doudouCard-popup-sect-child_right {
		height: 100%;
		padding-top: 17%;
		box-sizing: border-box;
	}

	.doudouCard-popup .doudouCard-popup-sect-child_right>view:first-child {
		width: 90px;
		height: 20px;
		border-radius: 4px;
		border: 1px solid #999999;
		display: flex;
		align-items: center;
		margin-bottom: 5px;
	}

	.doudouCard-popup .doudouCard-popup-sect-child_right>view:first-child view {
		height: 100%;
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.doudouCard-popup .doudouCard-popup-sect-child_right>view:first-child view:nth-child(2) {
		border-left: 1px solid #999999;
		border-right: 1px solid #999999;
	}

	.doudouCard-popup .doudouCard-popup-sect-child_right>view:last-child {
		font-size: 14px;
		font-family: 'PingFang SC-Medium';
		font-weight: 500;
		color: #37B79B;
		text-align: right;
	}

	.doudouCard-popup .doudouCard-popup-btn {
		position: absolute;
		bottom: 23px;
		left: 0;
		width: 100%;
		height: 2.5rem;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #fff;
	}

	.doudouCard-popup .doudouCard-popup-btn>view {
		width: 21.8rem;
		height: 2.5rem;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #32B499;
		border-radius: 20px;
		font-size: 14px;
		font-family: 'PingFang SC-Medium';
	}

	.modal-confirm {
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #fff;
		border-radius: 10px;
		height: auto;
		font-size: 14px;
		color: #333;
		box-sizing: border-box;
	}

	.modal-confirm-section {
		padding: 20px 30px;
		border-bottom: 1px solid rgba(241, 241, 241, 0.8);

	}

	.modal-confirm-section>.needPay-money {
		font-size: 24px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #EA5F5F;
		font-family: 'PingFang SC-Bold';
	}

	.modal-confirm-section>.toast-pay {
		margin-bottom: 12px;
		text-align: center;
		font-size: 12px;
		color: #999999;
	}

	.modal-confirm-section>view text {
		font-size: 20px;
		font-family: 'DIN-Bold';
	}

	.modal-confirm-section .pay-line {
		width: 100%;
		height: auto;
		display: block;
		margin: 12px 0;
	}

	.modal-confirm-section>.pay-type .pay-type-cont {
		display: flex;
		align-items: center;
		font-size: 14px;
		margin-left: 6px;
	}

	.modal-confirm-section>.pay-type .pay-type-cont>image {
		width: 24px;
		height: 24px;
		display: block;
		margin-right: 12px;
	}

	.modal-confirm-footer {
		height: 50px;
		display: flex;
		justify-content: center;
		align-items: center;
		box-sizing: border-box;
	}

	.modal-confirm-footer>view {
		flex: 1;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.modal-confirm-footer>view:last-child {
		border-left: 1px solid rgba(241, 241, 241, 0.8);
		color: #32B499;
	}

	.loading_title {
		padding-top: 20rpx;
	}

	.loading_popup {
		width: 600rpx;
		padding: 24rpx;
		background-color: #fff;
		border-radius: 20rpx;
	}

	.loading_popup .loading_box {
		overflow: auto;
		font-size: 30rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #666666;
		line-height: 45rpx;
	}

	.loading_btn {
		width: 140rpx;
		line-height: 65rpx;
		background-color: #32B499;
		margin: 50rpx auto;
		text-align: center;
		font-size: 28rpx;
		color: #fff;
		border-radius: 10rpx;


	}
</style>